package com.thoughtworks.recruit.test.jgraph.graph;

import com.thoughtworks.recruit.test.jgraph.interfaces.Graph;

import java.io.Serializable;

/**
 * A default implementation for edges in a {@link Graph}.
 *
 */
public class DefaultEdge
        implements Cloneable, Serializable
{
    private static final long serialVersionUID = 1L;

    Object source;

    Object target;

    /**
     * Retrieves the source of this edge. This is protected, for use by subclasses only (e.g. for
     * implementing toString).
     *
     * @return source of this edge
     */
    protected Object getSource()
    {
        return source;
    }

    /**
     * Retrieves the target of this edge. This is protected, for use by subclasses only (e.g. for
     * implementing toString).
     *
     * @return target of this edge
     */
    protected Object getTarget()
    {
        return target;
    }

    @Override
    public String toString()
    {
        return "(" + source + " : " + target + ")";
    }


    @Override
    public Object clone()
    {
        try {
            return super.clone();
        } catch (CloneNotSupportedException e) {
            // shouldn't happen as we are Cloneable
            throw new InternalError();
        }
    }
}
